var express = require('express');
var multipart = require('connect-multiparty');  //用来接收formdate的中间件

var multipartMiddleware = multipart();
var router = express.Router();
var Articles = require('../models/articles');
/* POST Articles listing. */
router.post('/', multipartMiddleware, function (req, res, next) {
    // 获取用户提交的信息
    console.log(req.body._id)
    var postData = {
        _id: req.body._id
    };
    const postArr = postData._id.split(',') //JSON.parse(postData._id);
    this.postArr = postArr;
        Articles.remove({ _id: { $in: postArr} }) // 删除多条数据
            .exec(function (err, data) {
                //console.log(data)
                if (data) {// 删除文章
                    console.log(data)
                    res.send({
                        state:1,
                        data:data //n代表成功删除几条
                    })
                } else {
                    //console.log(err)
                    res.send({
                        state:0,
                        data:data,
                        err:err
                    })
                }
            });
});

/* GET users listing. */
router.get('/', function (req, res, next) {
    var ArticleList = Articles.find({}, function (err, data) {
        if (err) throw err;
        res.send(data)
    });
})


module.exports = router;
